package com.zxl.register.server.socket;

import com.zxl.register.base.business.AnalyticalMsg;
import com.zxl.register.server.RegisterServer;

import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;

public class AcceptCompletionHandler implements CompletionHandler<AsynchronousSocketChannel,RegisterServer> {
    @Override
    public void completed(AsynchronousSocketChannel socketChannel, RegisterServer attachment) {
        // 处理下一次链接，类似链式调用
        attachment.getSocketChannel().accept(attachment,this);
        ByteBuffer buffer=ByteBuffer.allocate(1024);
        socketChannel.read(buffer,buffer,new ReadCompletionHandler(socketChannel,new AnalyticalMsg()));
    }

    @Override
    public void failed(Throwable throwable, RegisterServer registerServer) {
        throwable.printStackTrace();
    }

}
